import { taskState } from "@/util/guidingtextType";
const defaultTaskData = {
  chooseNo: 0,
  commentTime: 1630550490535,
  commentUserID: 0,
  currNo: 0,
  finishTime: 0,
  guidelineResults: {},
  startTime: 0,
  state: "未学",
  taskComment: "",
  taskID: 0,
  taskScore: -8,
  weightInGroup: 10,
}
const defaultGuidelineData = {
  // userID: null,
  // chooseNo: null,
  noInTask: null,
  commentTime: 0,
  guidelineID: null,
  weightInTask: 10,
  commentUserID: 0,
  submitContent: { data: null, isEncoded: false },
  guidelineScore: -8,
  lastUpdatedTime: 0,
  gameOrExciseRank: 0,
  guidelineComment: "",
  gameOrExciseScore: 0,
}
// 获取一个新的任务学习数据
export function getNewTaskStudyData(taskGroupID, taskItem, chooseNo, currNo) {
  let addAttribute = {
    chooseNo: chooseNo,
    currNo: currNo,
    guidelineResults: {},
    taskID: taskItem.taskID,
    taskGroupID: taskGroupID,
    state: taskState["unstudy"],
    notSaved: true,
  };

  taskItem.guidelines.forEach((gitem) => {
    addAttribute.guidelineResults[gitem.guidelineID] =
      getNewGuidelineStudyData(gitem);
  });
  return Object.assign({}, defaultTaskData, addAttribute);
}

// 获取一个新的引导文学习数据
export function getNewGuidelineStudyData(guidelineItem) {
  let addAttribute = {
    noInTask: guidelineItem.noInTask,
    guidelineID: guidelineItem.guidelineID,
    weightInTask: guidelineItem.weightInTask,
  };
  // 如果传递了学习数据进来时，使用原学习数据里面提交过的数据。
  if (guidelineItem.submitContent) addAttribute.submitContent = guidelineItem.submitContent
  if (guidelineItem.operType === "上传") {
    addAttribute.submitContent = {
      data: {
        baseFileUrl: "",
        filePaths: [],
      },
      // isEncoded: false,
    };
  }
  if (guidelineItem.operType === "展示") {
    addAttribute.submitContent = {
      data: {
        baseFileUrl: "",
        filePaths: [],
        showLink: ""
      }
    }
  }
  return Object.assign({}, defaultGuidelineData, addAttribute);
}

export default {
  getNewTaskStudyData,
  getNewGuidelineStudyData
}